<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>案例</title>
  </head>
  <body>
    <div class="box">
      <form action="">
        <label for="userName">
          用户名：
          <input type="text" id="userName" v-model.lazy="userValue" />
          <span>{{tip}}</span>
        </label>
      </form>
    </div>
    <script src="../node_modules/vue/dist/vue.js"></script>
    <script>
      new Vue({
        el: '.box',
        data: {
          userValue: '',
          tip: '',
        },
        methods: {
          get(val) {
            setTimeout(() => {
              val === 'admin' ? (this.tip = 'yes') : (this.tip = 'no')
            }, 1000)
          },
        },
        watch: {
          userValue: function (newValue) {
            this.tip = 'waite'
            this.get((b = newValue))
          },
        },
      })
    </script>
  </body>
</html>
